
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <netdb.h>
#include <dirent.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/syscall.h>

#include "common_util.h"
#include "common.h"

int FW_GetPID(void)
{
	return syscall(SYS_gettid);
}

/*====================================================================
 discrib: execute command instead of system api
 param: 
 	int FW_System(			-OUT SUCCESS/FAILURE
 			char *szCmd)		-IN command string
=====================================================================*/	
int FW_System(char *szCmd)
{
	pid_t pid = 0;
	int ret = SUCCESS;
	
	if (NULL == szCmd)
	{
		return FAILURE;
	}
	
	if (0 > (pid = fork()))
	{
		ret = FAILURE;
	}
	else if (0 == pid)
	{
		execl("/bin/sh", "sh", "-c", szCmd, NULL);
		exit(127);
	}
	else
	{
		while (0 > waitpid(pid, &ret, 0))
		{
			if (EINTR != errno)
			{
				ret = FAILURE;
				break;
			}
		}
	}
	
	return ret;
}


